clear all 
close all

load datafromstata gamma theta0 vMin vMax b1_mm_l b2_mm_l M meanxb

range =3;

figure(1)
 m=1;
   vSpace=linspace(vMin(m,range),vMax(m,range),100);
   p=zeros(1,100);
   pPrime=zeros(1,100);
   for j=1:100        
        p(j) = 0.075*exp(meanxb(m)+ b1_mm_l(m)*vSpace(j)+ b2_mm_l(m)*0.5*vSpace(j)*vSpace(j));
        pPrime(j) = p(j)*(b1_mm_l(m) + b2_mm_l(m)*vSpace(j));  
   end
   tempindex = pPrime>0; vSpace(tempindex) = NaN; p(tempindex) = NaN; p(tempindex) = NaN;
   subplot(2,1,1)
   hold all
   plot(max(vSpace)-vSpace,p,'Color',[0 0 0],'lineWidth',1.5),
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), p,'Color',[0 0 0]+0.5, 'lineWidth',1.5),
   xlabel('Safety Rate')
   ylabel('Annual User Cost of Housing')
   h = legend('$r(x)$','$\tilde{r}(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on
   subplot(2,1,2)
   hold all
   plot(max(vSpace)-vSpace,-pPrime,'Color',[0 0 0],'lineWidth',1.5)
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), -(inv(gamma(m))*pPrime),'Color',[0 0 0]+0.5, 'lineWidth',1.5)
   xlabel('Safety Rate')
   ylabel('Implicit Price of Safety')
   h = legend('$r\prime(x)$','$\tilde{r}\prime(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on 
   myfiguresize = [0, 1, 8.5, 5.0];
   set(gcf, 'PaperPosition', myfiguresize);
   colormap(gray)
   print -dpng pricegrad1 -r200

figure(2)
 m=2;
   vSpace=linspace(vMin(m,range),vMax(m,range),100);
   p=zeros(1,100);
   pPrime=zeros(1,100);
   for j=1:100        
        p(j) = 0.075*exp(meanxb(m)+ b1_mm_l(m)*vSpace(j)+ b2_mm_l(m)*0.5*vSpace(j)*vSpace(j));
        pPrime(j) = p(j)*(b1_mm_l(m) + b2_mm_l(m)*vSpace(j));  
   end
   tempindex = pPrime>0; vSpace(tempindex) = NaN; p(tempindex) = NaN; p(tempindex) = NaN;
   subplot(2,1,1)
   hold all
   plot(max(vSpace)-vSpace,p,'Color',[0 0 0],'lineWidth',1.5),
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), p,'Color',[0 0 0]+0.5, 'lineWidth',1.5),
   xlabel('Safety Rate')
   ylabel('Annual User Cost of Housing')
   h = legend('$r(x)$','$\tilde{r}(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on
   subplot(2,1,2)
   hold all
   plot(max(vSpace)-vSpace,-pPrime,'Color',[0 0 0],'lineWidth',1.5)
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), -(inv(gamma(m))*pPrime),'Color',[0 0 0]+0.5, 'lineWidth',1.5)
   xlabel('Safety Rate')
   ylabel('Implicit Price of Safety')
   h = legend('$r\prime(x)$','$\tilde{r}\prime(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on 
   myfiguresize = [0, 1, 8.5, 5.0];
   set(gcf, 'PaperPosition', myfiguresize);
   print -dpng pricegrad2 -r200
   
 figure(3)
 m=3;
   vSpace=linspace(vMin(m,range),vMax(m,range),100);
   p=zeros(1,100);
   pPrime=zeros(1,100);
   for j=1:100        
        p(j) = 0.075*exp(meanxb(m)+ b1_mm_l(m)*vSpace(j)+ b2_mm_l(m)*0.5*vSpace(j)*vSpace(j));
        pPrime(j) = p(j)*(b1_mm_l(m) + b2_mm_l(m)*vSpace(j));  
   end
   tempindex = pPrime>0; vSpace(tempindex) = NaN; p(tempindex) = NaN; p(tempindex) = NaN;
   subplot(2,1,1)
   hold all
   plot(max(vSpace)-vSpace,p,'Color',[0 0 0],'lineWidth',1.5),
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), p,'Color',[0 0 0]+0.5, 'lineWidth',1.5),
   xlabel('Safety Rate')
   ylabel('Annual User Cost of Housing')
   h = legend('$r(x)$','$\tilde{r}(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on
   subplot(2,1,2)
   hold all
   plot(max(vSpace)-vSpace,-pPrime,'Color',[0 0 0],'lineWidth',1.5)
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), -(inv(gamma(m))*pPrime),'Color',[0 0 0]+0.5, 'lineWidth',1.5)
   xlabel('Safety Rate')
    ylabel('Implicit Price of Safety')
   h = legend('$r\prime(x)$','$\tilde{r}\prime(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on 
   myfiguresize = [0, 1, 8.5, 5.0];
   set(gcf, 'PaperPosition', myfiguresize);
   print -dpng pricegrad3 -r200
   
   figure(4)
 m=4;
   vSpace=linspace(vMin(m,range),vMax(m,range),100);
   p=zeros(1,100);
   pPrime=zeros(1,100);
   for j=1:100        
        p(j) = 0.075*exp(meanxb(m)+ b1_mm_l(m)*vSpace(j)+ b2_mm_l(m)*0.5*vSpace(j)*vSpace(j));
        pPrime(j) = p(j)*(b1_mm_l(m) + b2_mm_l(m)*vSpace(j));  
   end
   tempindex = pPrime>0; vSpace(tempindex) = NaN; p(tempindex) = NaN; p(tempindex) = NaN;
   subplot(2,1,1)
   hold all
   plot(max(vSpace)-vSpace,p,'Color',[0 0 0],'lineWidth',1.5),
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), p,'Color',[0 0 0]+0.5, 'lineWidth',1.5),
   xlabel('Safety Rate')
   ylabel('Annual User Cost of Housing')
   h = legend('$r(x)$','$\tilde{r}(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on
   subplot(2,1,2)
   hold all
   plot(max(vSpace)-vSpace,-pPrime,'Color',[0 0 0],'lineWidth',1.5)
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), -(inv(gamma(m))*pPrime),'Color',[0 0 0]+0.5, 'lineWidth',1.5)
   xlabel('Safety Rate')
   ylabel('Implicit Price of Safety')
   h = legend('$r\prime(x)$','$\tilde{r}\prime(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on 
   myfiguresize = [0, 1, 8.5, 5.0];
   set(gcf, 'PaperPosition', myfiguresize);
   print -dpng pricegrad4 -r200
   
   figure(5)
 m=5;
   vSpace=linspace(vMin(m,range),vMax(m,range),100);
   p=zeros(1,100);
   pPrime=zeros(1,100);
   for j=1:100        
        p(j) = 0.075*exp(meanxb(m)+ b1_mm_l(m)*vSpace(j)+ b2_mm_l(m)*0.5*vSpace(j)*vSpace(j));
        pPrime(j) = p(j)*(b1_mm_l(m) + b2_mm_l(m)*vSpace(j));  
   end
   tempindex = pPrime>0; vSpace(tempindex) = NaN; p(tempindex) = NaN; p(tempindex) = NaN;
   subplot(2,1,1)
   hold all
   plot(max(vSpace)-vSpace,p,'Color',[0 0 0],'lineWidth',1.5),
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), p,'Color',[0 0 0]+0.5, 'lineWidth',1.5),
   xlabel('Safety Rate')
   ylabel('Annual User Cost of Housing')
   h = legend('$r(x)$','$\tilde{r}(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on
   subplot(2,1,2)
   hold all
   plot(max(vSpace)-vSpace,-pPrime,'Color',[0 0 0],'lineWidth',1.5)
   plot(max(vSpace)-(theta0(m)+gamma(m)*vSpace), -(inv(gamma(m))*pPrime),'Color',[0 0 0]+0.5, 'lineWidth',1.5)
   xlabel('Safety Rate')
   ylabel('Implicit Price of Safety')
   h = legend('$r\prime(x)$','$\tilde{r}\prime(\bar{x})$','Location','northwest');
   set(h,'Interpreter','latex', 'fontsize', 14)
   grid on 
   myfiguresize = [0, 1, 8.5, 5.0];
   set(gcf, 'PaperPosition', myfiguresize);
   print -dpng pricegrad5 -r200

